﻿using CardMonitor.Model;
using CardMonitor.Windows;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CardMonitor.Pages
{
    /// <summary>
    /// MakeReports.xaml 的交互逻辑
    /// </summary>
    public partial class MakeReports : Page
    {
        private SynchronizationContext _syncContext = null;
        private ImageBrush imageBrush;
        private List<BillModel> items = new List<BillModel>();
        private MainWindow mainWindow = null;

        public MakeReports(List<BillModel> bills, MainWindow _win)
        {
            InitializeComponent();
            mainWindow = _win;

            for (int i = 0; i < bills.Count; i++)
            {
                BillModel bill = bills[i];
                if ("0".Equals(bill.Type))
                {
                    bill.Type = "装车业务";
                }
                if ("1".Equals(bill.Type))
                {
                    bill.Type = "卸车业务";
                }
            }
            items = bills;

            listView.ItemsSource = items;
        }

        public void setPersonImage(ImageBrush image)
        {
            this.imageBrush = image;
        }

        private void Button_Click_GoReport(object sender, RoutedEventArgs e)//报道按钮
        {
            mainWindow.Speak("请再次确认计划信息，确认无误后点击报到按钮，报到完成后请取走身份证");

            var btn = sender as Button;
            BillModel item = btn.DataContext as BillModel;

            if (item.Type.Equals("装车业务") || item.Type.Equals("采购退货业务"))
            {
                Cards buycard = new Cards(item, mainWindow);
                if (null != imageBrush)
                {
                    buycard.setPersonImage(imageBrush);
                }
                NavigationService.GetNavigationService(this).Navigate(buycard);
            }

        }

        private void goIndex(object sender, RoutedEventArgs e)
        {
            NavigationService.GetNavigationService(this).GoBack();
        }

        private void showMessage(String message)
        {
            InfoWindow infoWindow = new InfoWindow(message);
            infoWindow.Owner = mainWindow;
            infoWindow.ShowDialog();
        }
    }
}